<template>
	<view class="wrongTopic">
		<view class="" v-if="load">
			<view class="wt-head">
				<view class="number">{{ number }}</view>
				<view class="text">总错题量</view>
			</view>
			<view class="su-main">
				<view class="item item-b" v-for="(item, index) in setUpList" :key="index" @click="onSetUp(item, index)">
					<view class="left">{{ item.title }}</view>
					<view class="right">
						<text>{{ item.num }}</text>
						<!-- <image src="/static/xs_icon/right3.png" mode="widthFix"></image> -->
						<image src="../../../static/xs_icon/right3.png" mode="widthFix"></image>
					</view>
				</view>
			</view>
		</view>

		<!-- <view class="pd-buttom"><view class="pdb-con" @click="onReturn()">退出登录</view></view> -->
		<view class="load"  v-else>
			<u-loading size="80" mode="flower"></u-loading>
		</view>
	</view>
</template>

<script>
// import { mapState, mapMutations } from "vuex";
import { VERSION_CODE } from '@/common/config.js';
import successPop from '@/components/xs-components/success-pop/success-pop.vue';
export default {
	components: { successPop },
	data() {
		return {
			load: false,
			login: false,
			setUpList: [],
			showPopup: false, // 清除成功弹窗
			number: 0 // 错题总量
		};
	},
	onLoad() {
		this.into();
		uni.$on('update', data => {
			this.postData();
		});
	},
	methods: {
		// ...mapMutations(['getAddress','auoutUS']),
		into() {
			this.postData();
		},
		// 获取错题集
		postData() {
			this.$api
				.post(global.apiUrls.wrongQuestions)
				.then(res => {
					console.log(res.data);
					this.load = true;
					if (res.data.code == 1) {
						this.setUpList = res.data.data;
						// number
						let number = 0;
						for (let i in this.setUpList) {
							number += this.setUpList[i].num;
						}
						this.number = number;
						// this.getAddress(res.data.data);
					}
				})
				.catch(err => {
					// this.$popup.showToast('保存失败')
				});
		},
		// 列表点击事件
		onSetUp(item, index) {
			console.log(item, index);
			uni.navigateTo({
				url: '../wrongDetails/wrongDetails?course_id=' + item.course_id
			});
		},
		// 同意
		confirm() {
			console.log('同意');
			// type  0 缓存 1 版本号
			if (this.type == 0) {
				this.$popup.showLoading('正在清除缓存...');
				uni.removeStorageSync('CACHE_SIZE');
				setTimeout(() => {
					uni.hideLoading();
					this.CACHE_SIZE = uni.getStorageSync('CACHE_SIZE') || 0;
					this.showPopup = true;
				}, 3000);
			} else {
			}
		},
		// 取消
		cancel() {
			console.log('取消');
		},
		// 确定弹窗
		determine(e) {
			this.showPopup = e;
		},
		// 退出
		onReturn() {
			this.login = true;
		},
		loginOut() {
			uni.removeStorageSync('USER_INFO');
			uni.removeStorageSync('USER_TOKEN');
			uni.reLaunch({
				url: '/pages/login/login/index'
			});
		}
	}
};
</script>

<style lang="scss" scoped>
@import './wrongTopic.scss';
</style>
